//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import modelBody from "@/views/mytable/mytable/Fk_flow.vue";
var _alldata;
let extension = {
	components: { //动态扩充组件或组件路径
		//表单header、content、footer对应位置扩充的组件
		gridHeader:  '',//,{ template: "大幅度" },
		gridBody: '',
		gridFooter: '',
		//弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
		modelHeader: '',
		modelBody: modelBody,
		modelFooter: ''
	},
	text: "当前用户只能看到所属的部门成本中心授权后的预算",
	buttons: {
		view: [],
		box: [],
		detail: []
	}, //扩展的按钮
	methods: { //事件扩展
		onInit() {
			this.summary = true;
			this.columnIndex = true;
			//this.continueAdd=true;
			//this.continueAddName="连续添加";
			this.boxOptions.saveClose=false;//弹出窗口中保存后不关闭弹出窗体

		},
		onInited() {
			
		 let c = {
				field: "total_sum",
				title: "年度合计",
				width: 100,
			 align: "center",
				render: (h, {
					row,
					column,
					index
				}) => {
					// console.log(column)
					return (row.tsl01 + row.tsl02 + row.tsl03 + row.tsl04 + row.tsl05 + row.tsl06 + row
						.tsl07 + row.tsl08 + row.tsl09 + row.tsl10 + row.tsl11 + row.tsl12).toFixed(2);
				}
			}
			this.columns.splice(4, 0, c); //在第5列插入字段

			this.columns.forEach(x => {	
				//系统bug，列冻结和合计不能同时使用
				if (x.field.indexOf('tsl') >= 0) {
					x.summary = true;
				}
			})
			
			//this.editFormFields.gjahr=this.base.getDate().getFullYear;

				//x.gjahr=this.base.getDate().getYear();
			
			this.columns.forEach(x => {	
				if((x.field =='total_sum') ||(x.field =='gjahr')||(x.field =='racct')||(x.field =='rcntr')){
					//console.log(x.fixed)
					x.fixed=true;
					//console.log(x.fixed)
				}
				if(x.field=="gjahr"){
					x.cellStyle = (row, rowIndex, columnIndex) => { //相当于给X增加属性 cellStyle
						//console.log(_alldata.extra.flows)
						//console.log(row)
						/* _alldata.extra.ys_query.some(x => {
							return x.racct === row.fei_type && x.rcntr === row.rcntr
						}); */
						//console.log(_alldata.extra.flows.some(s=>{ return (s.rcntr=="9000100001" && s.racct=="6602010105")}));
						if(_alldata.extra.flows.some(s=>{ return (s.rcntr==row.rcntr && s.racct==row.racct)})){//some一定要有return
						//	console.log(1)
							return {
								background: "#00FF00"
							}
						}
						
					}
				}
				
			});
			setTimeout(() => {
				this.$nextTick(() => {	
					let sum_t=0;
					for(let i=6;i<=17;i++){
						sum_t=sum_t+this.$refs.table.summaryData[i]*1;
					}
					this.$refs.table.summaryData[5]=sum_t.toFixed(2);//保留两位小数
					//console.log(this.$refs.table.summaryData)		
				})
			}, 500);
			//console.log(this.columns)
			
		},
		modelOpenAfter(row) {
			if (this.currentAction == "Add") { //只有新增数据的界面才给初始值
				let date = new Date();
				let year = date.getFullYear();
				this.editFormFields.gjahr=year;			
			}
			this.$nextTick(() => {
				
				if (row===undefined){
					var myDate = new Date();
					//console.log(myDate);
					this.$store.getters.data().racct="-"+myDate//随便用个参数假装查询一下viewgrid控件，因为viewgrid控件查询后不容易处理状态2022年6月6日 13:46:44
					this.$store.getters.data().rcntr="-"+myDate	
							
				}else{
					this.$store.getters.data().racct=row.racct
					this.$store.getters.data().rcntr=row.rcntr	
				}
				this.$refs.modelBody.$refs.grid.refresh();
				
				
			})
			//console.log("year");
			
		},
		searchAfter(result, alldata) { //查询ViewGird表数据后param查询参数,result回返查询的结果
			_alldata = alldata; //查询后从服务器传入所有数据  huangxs
			return true;
		},
		 onModelClose(iconClick){
		    
		   //var self=this;
		   setTimeout(() => {
		   	this.$nextTick(() => {	
		   		let sum_t=0;
		   		for(let i=6;i<=17;i++){
		   			sum_t=sum_t+this.$refs.table.summaryData[i]*1;
		   		}
		   		this.$refs.table.summaryData[5]=sum_t.toFixed(2);
		   		//console.log(this.$refs.table.summaryData)
				//this.$store.getters.data().rcntr=null 
				//this.$store.getters.data().racct=null
				//this.$refs.modelBody.$refs.grid.refresh();		
		   	})
		   }, 600);
		   // this.$refs.modelBody.$refs.grid.refresh();
		   // console.log(this.$refs.modelBody.$refs.grid);
		    this.refresh();
			
		    this.boxModel=false;
		  },
	},
};
export default extension;
